The present invention relates to managing a limited resource that is reusable by multiple entities within a computer system. In particular, the present invention is directed to retaining an amount of the resource used by an entity for a minimum period of time after the entity terminates execution.
Computer systems include computer hardware, such as one or more processors and one or more storage devices, and software entities made up of instructions for causing the processors to perform one or more related tasks. Limits on the amount of resources in the computer system have impacts on the software systems executing on the hardware to perform the related tasks. For example, the amount of memory limits how much data a processor can access quickly; the amount of durable storage limits the amount of data that can be stored in a database; and the communications bandwidth limits the number and size of messages that can be exchanged with other devices connected to the computer.
One way that limited resources can be employed by computer systems to perform more, larger and more complex tasks, is to reuse some resources when possible. For example, a large amount of sort space in memory facilitates sorting a large number of results from a query of a large database, but the space in memory is free after the sort is completed and can be used to perform a second sort. The sort space in memory is an example of a reusable resource. Cache space in memory for temporarily holding data from several blocks of a storage medium is another example of a reusable resource. Another example of a reusable resource is communications bandwidth. A large amount of bandwidth is consumed to send a video clip or audio track, but the same bandwidth is available to send another message, clip or track after the first clip or track is transmitted.
Durable storage is typically consumed by a computer system for relatively permanent uses, such as storing data and software. Durable storage is often not a reusable resource for a computer system; typically, as more data ate stored, more durable storage is consumed. However, an example in which durable storage is reusable is the durable storage of undo information. Some entities of the computer system include transactions that make changes to the computer system, such as changing the data stored in a database or changing the state of equipment controlled by the computer system. These transactions might involve hundreds or millions of operations and take minutes or hours to complete. If a transaction does not complete successfully, then the data in the database or the equipment is in some interim state that is not planned and that is probably not desired. It is therefore conventional for the transaction to generate and store in an undo storage space an undo log of data indicating operations to perform to reverse the operations performed during the transaction. Then, if the transaction fails to complete successfully, the changes to the computer system are undone, following the operations in the undo log from last to first. The undo operations restore the computer system to a state before the transaction began, a state that was planned, at least at one point in time, and that is preferable to the unplanned interim state. The durable storage employed to store the undo log is a reusable resource. After the transaction completes, or after the unsuccessful transaction is undone, the undo data in the storage is considered obsolete and the storage allocated to the undo data is re-allocated to another transaction.
Computer systems typically manage reusable resources by reserving some or all of the resource for a particular entity of the computer system and freeing the resource for other entities when the particular entity terminates execution. However, some use may be made of the reusable resource in a given state even after the entity that generated it terminates, and the conventional computer systems do not guarantee the resource will be retained in a given state long enough to support the other uses.
For example, the information in the undo log for a transaction involving a database is used to provide consistent reads of data in a database. A consistent read is an entity of a database system that allows a user of the database to query a database even while transactions are ongoing to change the data in the database. The consistent read is designed to provide data from the database that reflects the last planned state of the database at the time the query is issued. The consistent read handles data involved in an ongoing transaction by using the undo log in the undo durable storage to determine the state of the data before the transaction began operating on the data. Problems may arise if the undo log in the durable undo storage is not retained long enough.
For example, a complex reading query involving thousands of rows of one or more tables may require some minutes to complete. This is not a transaction because the reading query does not change the data in the database. The reading query is allowed to progress even though an update transaction involving some of the same rows is already ongoing, or commences shortly after the reading query is started. While the query causes data to be read from other rows of the tables, a particular row is changed by the transaction and the reverse operation is stored in the reusable undo durable storage. When the query gets to the particular row, the consistent read entity determines that the row has been changed since the start of the query and that the undo log is to be used to reconstruct the state of the row before the transaction started. However, before the consistent read entity retrieves the undo log from durable storage, the transaction completes and commits the changes to the database. The durable storage allocated to the transaction is now available for another transaction. A second transaction begins and reuses the storage space formerly allocated to the first transaction. When the consistent read entity attempts to retrieve the undo log of the first transaction, it finds instead information from the undo log of the second transaction. The consistent read cannot obtain the correct undo information, and the state of the data before the first transaction cannot be reconstructed. The consistent read fails because the undo information was not retained long enough after the transaction was completed to support the use of the undo information by the consistent read entity.
Similar situations may arise if other reusable resources are re-allocated as soon as the entity that generated them terminates and if other entities attempt to retrieve the resource in the state left by the generating entity. While the immediate re-allocation of the reusable resource is sometimes undesirable, it is also undesirable to retain the resource permanently or indefinitely in the state left by the generating entity. Retaining the resource indefinitely in a given state inhibits the reuse of the resource.
Clearly, there is a need for techniques to manage reusable resources, which recycle the resources for new uses by other entities, but that also guarantee the resources are retained in a given state for consistent use by other entities, even after termination of the entity that first had the resource allocated.
According to one aspect of the invention, techniques for managing, within a computer system, a resource that is reusable by a plurality of entities include establishing a minimum period of time for retaining an amount of the resource after completion of use of the resource by an entity. A first amount of the resource is allocated to a first entity. After allocating the first amount to the first entity, the first amount is prevented from being allocated to a second entity before the minimum period of time expires after the first entity completes use of the first resource.
According to another aspect of the invention, techniques for managing changes in a computer system include, when a first entity makes changes in a computer system, durably storing, in a first storage space, first information about how to remove the changes. After the first entity has terminated, the first information is retained in the first storage space for a time based on a specified minimum amount of time.
According to another aspect of the invention, techniques for managing changes in a computer system include, when a first entity makes changes in a computer system, durably storing, in a first storage space, first information about how to remove the changes. Second information is durably stored in a second storage space. The second information includes data indicating the first storage space and the first entity. When the first entity terminates, data is stored in the second storage space, the data indicating an actual time when the first entity terminates. After the first entity has terminated, the first information is retained in the first storage space for a specified minimum amount of actual time. The retaining step includes, when a second entity makes changes in the computer system at a first time, retrieving from the second storage space the data indicating the actual time when the first entity terminates. It is then determined whether the first time is after the actual time when the first entity terminates by at least the specified minimum amount of actual time. If so, then third information is durably stored in the second storage space. The third information includes data indicating the first storage space and the second entity. Then, fourth information about how to remove changes made by the second entity is durably stored in the first storage space.
These techniques allow resources to be recycled and allocated for new uses by other entities in a computer system, but also guarantee the resources are retained in a given state for consistent use by other entities, even after termination of the entity that first had the resource allocated.